<style >
	@import url("../../../common/css/address.css");
</style>
<template>
	<view>
		<commonHeader :titleName="titleName"></commonHeader>
		<view class="content_info_no_margin" style="padding-bottom: 100rpx;">
			<view class="address_item" v-for="(item,index) in addressList" :key="index">
				<view class="address_left" @click="chooseAddress(item.id)">
					<view class="addressCity">{{item.address}}</view>
					<view class="addressInfo">{{item.detailedAddress}}</view>
					<view class="addressUserInfo">
						<text class="addressUserInfo_username">{{item.contacts}}</text>
						<text class="addressUserInfo_phone">{{item.contactPhone}}</text>
					</view>
				</view>
				<view class="address_right" @click="editAddress($event,item)">
					<image class="address_edit" src="../../../static/edit2.png" mode="aspectFill"></image>
				</view>
			</view>
		</view>
		<view class="add_address">
			<view class="add_address_btn" @click="addAddress">新增收货地址</view>
		</view>
	</view>
</template>

<script>
	import commonHeader from '@/components/common-header/common_header_title.vue';
	export default{
		components:{
			commonHeader
		},
		onLoad() {
			
		},
		onShow() {
			this.initAddressList()
		},
		data(){
			return {
				titleName:"常用地址",
				addressList:[]
			}
		},
		methods:{
			initAddressList(){
				let that = this
				this.$api.address.userAddressList()
				.then(res => {
					if(res.code == 200){
						let data = res.data
						if(data.length > 0 ){
							that.addressList = data
						}
					}else{
						this.$commonJs.showToast.showNoneToast(res.msg)
					}
				})
				.catch(err => {
					this.$commonJs.showToast.showNoneToast(err)
				})
			},
			editAddress(e,item){
				console.log(item)
				let pj_str 	=	"?id="+item.id +"&cityName=" +item.address + "&addressInfo=" + item.detailedAddress + "&username=" + item.contacts + "&phone="+item.contactPhone +"&sex=" + item.sex + "&lon=" + item.longitude + "&lat=" + item.latitude
				this.$uniNavigateTo('../../../pages/address/edit-address/edit-address'+pj_str)
			},
			addAddress(){
				this.$uniNavigateTo('../../../pages/address/add-address/add-address')
			},
			chooseAddress(id){
				let postData = {id:id}
				this.$api.address.setDefaultAddress(postData)
				.then(res => {
					if(res.code == 200){
						uni.navigateBack({
							delta:1
						})
					}else{
						this.$commonJs.showToast.showNoneToast(res.msg)
					}
				})
				.catch(err => {
					this.$commonJs.showToast.showNoneToast(err)
				})
			}
		}
	}
</script>
